import requests
import json

# 替换成自己的QQ API密钥和目标QQ ID
ACCESS_TOKEN = 'YOUR_ACCESS_TOKEN'
TARGET_QQ_ID = 'TARGET_QQ_ID'

# QQ API请求URL
URL = 'http://api.qzone.cc/get/user_info'

# 构造请求参数和头部
params = {'user_id': TARGET_QQ_ID}
headers = {'Authorization': f'Bearer {ACCESS_TOKEN}'}

# 发送请求并获取响应
response = requests.get(URL, headers=headers, params=params)

# 解析响应JSON数据
data = json.loads(response.text)

# 提取用户资料信息
nickname = data['nickname']
gender = data['gender']
age = data['age']
location = data['location']
signature = data['signature']

# 输出用户资料信息
print('Nickname:', nickname)
print('Gender:', gender)
print('Age:', age)
print('Location:', location)
print('Signature:', signature)

# 保存用户资料信息到文本文件
with open('user_info.txt', 'w', encoding='utf-8') as f:
    f.write(f'Nickname: {nickname}\n')
    f.write(f'Gender: {gender}\n')
    f.write(f'Age: {age}\n')
    f.write(f'Location: {location}\n')
    f.write(f'Signature: {signature}\n')

print('用户资料已保存到user_info.txt文件中。')
